# -*- coding: utf-8 -*-
# @Time : 2021/2/3 13:44
# @Author : shx
# @Email : 925126486@qq.com
# @File : contract_page.py
# @Project : test
from selenium.webdriver.common.by import By
from pages.base_page import BasePage

class ContractPage(BasePage):
    """定义合同页面"""
    url_ = 'http://192.168.1.49/crm3/index.php?m=contract'
    ht_tbody_locator = (By.TAG_NAME, 'tbody')
    tr_locator = (By.TAG_NAME, 'tr')
    td_locator = (By.TAG_NAME, 'td')
    td_input_locator = (By.TAG_NAME, 'input')
    td_a_locator = (By.LINK_TEXT, '查看')
    td_aa_locator = (By.LINK_TEXT, '编辑')
    add_contract_locator = (By.LINK_TEXT,'添加合同')
    tbody_locator =(By.CSS_SELECTOR,'#form1 > table > tbody')

    def get_current_url(self):
        return self.driver.current_url

    def check_contract(self,col,contract_no):
        """查看一条合同信息"""
        tbody_element = self.find_element(self.ht_tbody_locator)
        trs = tbody_element.find_elements(*self.tr_locator)
        for tr in trs:
            tds = tr.find_elements(*self.td_locator)
            if tds[col-1].text == contract_no:
                tds[col+7].find_element(*self.td_a_locator).click()
                break

    def editor_contract(self,col,contract_no):
        """编辑一条合同信息"""
        tbody_element = self.find_element(self.ht_tbody_locator)
        trs = tbody_element.find_elements(*self.tr_locator)
        for tr in trs:
            tds = tr.find_elements(*self.td_locator)
            if tds[col-1].text == contract_no:
                tds[col+7].find_element(*self.td_aa_locator).click()
                break

    def point_add_co(self):
        """点击添加合同"""
        self.find_element(self.add_contract_locator).click()

    def tbody_element(self):
        return self.find_element(self.tbody_locator)
